#ifndef BLDCDRIVER_H
#define BLDCDRIVER_H
#include "stdbool.h"
typedef enum {
  PHASE_OFF = 0, // both sides of the phase are off
  PHASE_ON = 1,  // both sides of the phase are driven with PWM, dead time is applied in 6-PWM mode
  PHASE_HI = 2,  // only the high side of the phase is driven with PWM (6-PWM mode only)
  PHASE_LO = 3,  // only the low side of the phase is driven with PWM (6-PWM mode only)
}PhaseState;
typedef void (*BLDCDriver_Set_PWM)(float Ua,float Ub,float Uc);
typedef void (*BLDCDriver_PhaseState)(PhaseState sa,PhaseState sb,PhaseState sc);
typedef void (*BLDCDriver_State)(void);
/// 三相PWM占空比
typedef struct
{
    float dc_a;
    float dc_b;
    float dc_c;
}Phase_DutyCycle_t;
/// 函数
typedef struct 
{
    BLDCDriver_Set_PWM      setPwm;
    BLDCDriver_PhaseState   setPhaseState;
    BLDCDriver_State        disable;
    BLDCDriver_State        enable;
}BCDCDriver_Function_t;

typedef struct 
{
    long pwm_frequency; //!< pwm frequency value in hertz
    float voltage_power_supply; //!< power supply voltage
    float voltage_limit; //!< limiting voltage set to the motor
    Phase_DutyCycle_t phase;
    BCDCDriver_Function_t function;
    bool initialized;
}BLDCDriver_t;

void BLDCDriver_Init(BLDCDriver_t *handle);

void BLDC_SetPWM(BLDCDriver_t *handle,float Ua, float Ub, float Uc);
void BLDC_SetPhaseState(BLDCDriver_t *handle,PhaseState a,PhaseState b,PhaseState c);
void BLDC_disable(BLDCDriver_t *handle);
void BLDC_enable(BLDCDriver_t *handle);
#endif
